﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Xml.Linq;
using Sync;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;

namespace TaskSync2010
{
    public partial class ThisAddIn
    {
        public  static Timer Timer; 

        private static Syncer _syncer;
        public static Syncer Syncer
        {
            get { return _syncer ?? (_syncer = new Syncer(UserSettings.Username, UserSettings.Password)); }
            set { _syncer = value; }
        }


        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            Timer = new Timer(Sync);
            Timer.Change(5000, UserSettings.Interval*60*1000);
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            Syncer.Sync();
        }

        private void Sync(object state)
        {
            Syncer.Sync();
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }
}
